<!--学生发布文章-->
<style>
	.yanse {
		width: 20px;
		height: 20px;
		display: inline-block;
		line-height: 20px;
	}
	
	.xiaofangkuai {
		display: inline-block;
	}
	
	.modal-dialog {
		width: 100%;
		margin: 30px auto;
	}
	
	#title {
		width: 400px;
	}
</style>

<div class="modal-dialog" role="document">
	<div class="modal-content">
		<div class="modal-header">
			<div class="input-group" style="float: left;">
				<input type="text" id="title" class="form-control" placeholder="请输入标题">
			</div>
			<button type="button" class="btn btn-primary" style="float: right;">发布文章</button>
		</div>
		<div class="modal-body">
			<div class="input-group">
				<span class="input-group-addon" id="basic-addon1">文章内容</span>
				<script id="editor" type="text/plain" charset="utf-8" style="width: 100%; height: 360px;"></script>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" charset="utf-8">
	//实例化编辑器
	UE.delEditor('editor');
	//建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
	var ue = UE.getEditor('editor', {
		initialFrameWidth: '100%', //设置编辑器宽度
		scaleEnabled: true, //设置不自动调整高度
		//scaleEnabled {Boolean} [默认值：false]//是否可以拉伸长高，(设置true开启时，自动长高失效)
		toolbars: [
			['toggletool', 'fullscreen', 'source', '|', 'undo', 'redo', '|',
				'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript',
				'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|',
				'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|',
				'simpleupload', 'insertimage', '|', 'selectall', 'cleardoc'
			]
		]
	});
</script>

<script>
	$('.btn').click(function() {
		var obj = {
			title: $('#title').val(),
			content: UE.getEditor('editor').getContent()
		}
		$.ajax({
			xhrFields: {
				withCredentials: true
			},
			type: 'POST',
			url: getFullURL('user/add-article'),
			data: obj,
			success: function(data) {
				if(data.status == 0) {
					alert('发布成功', function() {
					$(location).attr('href', './homt.html');
				})
				} else if(data.status == -1) {
					alert('发布失败');
				}
			},
			error: function(err) {
				alert("请求异常，请重新登录！", function() {
					$(location).attr('href', './login.html');
				})
			}
		})
	})
</script>